Geopandas 对点(几何)到线串
Geopandas pair of points (geometry) to linestring
如您所见,我对此完全是个新手。我想从两个 POINT 几何图形创建一个 LINESTRING,然后确定中点。因此,从我原来的 pandas 数据框,x 和 y 列,我创建了以下 geopandas 数据框:
zone_short_edges =
id vertex_id from \
1 A1 2 POINT (119.79008 28.35047)
3 A1 4 POINT (122.85067 44.85106)
5 A2 1 POINT (138.79141 26.48802)
7 A2 3 POINT (141.73386 44.89716)
to seg_length
1 POINT (122.85067 28.08433) 3.072140
3 POINT (119.92314 44.71798) 2.930553
5 POINT (141.92247 26.26168) 3.139230
7 POINT (138.79141 44.89716) 2.942450
其中 fr_point
和 to_point
是 dtype = geomtry
.
现在,我面临两个选择:
- 为每对创建一个 LINESTRING,然后找到该线串的中点。
- 找到中点(我实际上想要找到将线段分成
N
个等长线段的所有点的可能性)。
我试过这样做:
geometry = [xy for xy in zip(zone_short_edges.fr_point, zone_short_edges.to_point)]
LineString([geometry]).wkt
我也尝试了这里提供的解决方案:
但是,都失败了。
有什么想法可以让我朝着正确的方向前进,或者我真的需要转到我的原始数据框吗?
如果您的目标是获得中点,那么您可以改用一些数学方法。它还会为您节省一些 运行 时间,我相信...我已经有一段时间没有接触 python-gis 了,但也许这会对您有所帮助。
伪代码:
# lat1,lat2,lon1,lon2 should be in radian
Bx = cos(lat2) * cos(lon2-lon1);
By = cos(lat2) * sin(lon2-lon1);
latMid = atan2(sin(lat1) + sin(lat2),
sqrt( (cos(lat1)+Bx)*(cos(lat1)+Bx) + By*By ) );
lonMid = lon1 + atan2(By, cos(lat1) + Bx);
您没有指定坐标系,因此计算可能有误,快速搜索应该会给您正确的解决方案。
此外,这种交流也可以帮助你
如何计算python中几个地理位置的中点
如您所见,我对此完全是个新手。我想从两个 POINT 几何图形创建一个 LINESTRING,然后确定中点。因此,从我原来的 pandas 数据框,x 和 y 列,我创建了以下 geopandas 数据框:
zone_short_edges =
id vertex_id from \
1 A1 2 POINT (119.79008 28.35047)
3 A1 4 POINT (122.85067 44.85106)
5 A2 1 POINT (138.79141 26.48802)
7 A2 3 POINT (141.73386 44.89716)
to seg_length
1 POINT (122.85067 28.08433) 3.072140
3 POINT (119.92314 44.71798) 2.930553
5 POINT (141.92247 26.26168) 3.139230
7 POINT (138.79141 44.89716) 2.942450
其中 fr_point
和 to_point
是 dtype = geomtry
.
现在,我面临两个选择:
- 为每对创建一个 LINESTRING,然后找到该线串的中点。
- 找到中点(我实际上想要找到将线段分成
N
个等长线段的所有点的可能性)。
我试过这样做:
geometry = [xy for xy in zip(zone_short_edges.fr_point, zone_short_edges.to_point)]
LineString([geometry]).wkt
我也尝试了这里提供的解决方案:
但是,都失败了。
有什么想法可以让我朝着正确的方向前进,或者我真的需要转到我的原始数据框吗?
如果您的目标是获得中点,那么您可以改用一些数学方法。它还会为您节省一些 运行 时间,我相信...我已经有一段时间没有接触 python-gis 了,但也许这会对您有所帮助。
伪代码:
# lat1,lat2,lon1,lon2 should be in radian
Bx = cos(lat2) * cos(lon2-lon1);
By = cos(lat2) * sin(lon2-lon1);
latMid = atan2(sin(lat1) + sin(lat2),
sqrt( (cos(lat1)+Bx)*(cos(lat1)+Bx) + By*By ) );
lonMid = lon1 + atan2(By, cos(lat1) + Bx);
您没有指定坐标系,因此计算可能有误,快速搜索应该会给您正确的解决方案。 此外,这种交流也可以帮助你 如何计算python中几个地理位置的中点